import Vue from 'vue'
import VueRouter from 'vue-router'


Vue.use(VueRouter)

const routes = [
  {
      path:'/',
      redirect:'/login'
  },
  {
    path: '/login',
    component: () => import( '../views/login/index.vue')
  },
  {
    path: '/index',
    component: () => import( '../views/index/index.vue'),
    children:[
      {
        path: '/menu',
        component: () => import( '../views/menu/index.vue')
      },
      {
        path:'/menu',
        redirect:'/menu'
    },
    ]
  },
]

const router = new VueRouter({
 
  routes
})

export default router

router.beforeEach((to,from,next)=>{
   let userInfo=localStorage.getItem('userInfo')||""

   if(userInfo==""&&to.path!="/login"){
      alert('请先登录')
      next('/login')
   }else{
      next()
   }
})

